FROM python:3.10-slim

LABEL maintainer="Llama Distributed Team <info@llamadistributed.example.com>"
LABEL description="Cloud-native distributed query processor for llama_vector shards"
LABEL version="0.1.0"

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PYTHONFAULTHANDLER=1 \
    PIP_NO_CACHE_DIR=off \
    PIP_DISABLE_PIP_VERSION_CHECK=on

# Create a non-root user
RUN groupadd -r llamauser && useradd -r -g llamauser llamauser

# Create app directory and set permissions
WORKDIR /app
RUN chown llamauser:llamauser /app

# Install dependencies
COPY --chown=llamauser:llamauser requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy package files
COPY --chown=llamauser:llamauser . .

# Install the package
RUN pip install --no-cache-dir -e .

# Switch to non-root user
USER llamauser

# Expose the server port
EXPOSE 8080

# Set default environment variables for the app
ENV LLAMA_DISTRIBUTED_API_KEY="" \
    KUBERNETES_NAMESPACE="default" \
    LOG_LEVEL="INFO"

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD curl -f http://localhost:8080/api/health || exit 1

# Run the server
CMD ["llama-distributed-server", "--host", "0.0.0.0", "--port", "8080", "--log-level", "${LOG_LEVEL}"]
